#coding=utf-8
import urllib

class SpiderUtil:

    def __init__(self):
        # 配置项
        # 设置代理IP
        self.proxy_addr = "221.1.200.242:38652"

    # 定义页面打开函数
    # 定义爬虫配置
    def use_proxy(self,url):
        req = urllib.request.Request(url)
        req.add_header("User-Agent",
                       "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0")
        proxy = urllib.request.ProxyHandler({'http': self.proxy_addr})
        opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)
        urllib.request.install_opener(opener)
        data = urllib.request.urlopen(req).read().decode('utf-8', 'ignore')
        print(data)
        return data

spiderUtil = SpiderUtil()